package com.nineclock.document.controller;

import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.document.dto.*;
import com.nineclock.document.service.DocCollaborationsService;
import com.nineclock.document.service.DocFileService;
import com.nineclock.document.service.DocFolderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Api(value = "APP文件管理接口", tags = "文档服务")
public class DocumentController {
    @Autowired
    private DocFileService docFileService;
    @Autowired
    private DocFolderService docFolderService;
    @Autowired
    private DocCollaborationsService docCollaborationsService;

    /**
     * 查询当前目录下的文件夹及文件
     * 接口路径：GET/document/listFolderAndFile
     */
    @GetMapping("listFolderAndFile")
    @ApiOperation(value = "查询当前目录下的文件夹及文件")
    public Result<DocumentDto> listFolderAndFile(Long parentFoldId){
        DocumentDto documentDto = docFileService.listFolderAndFile(parentFoldId);
        return Result.success(documentDto);
    }
    /**
     * 新增文件夹
     * 接口路径：POST/document/insertFolder
     */
    @ApiOperation(value = "新增文件夹")
    @PostMapping("insertFolder")
    public Result insertFolder(@RequestBody DocFolderDto docFolderDto){
        docFolderService.insertFolder(docFolderDto);
        return Result.success();
    }
    /**
     * 根据文档ID查询文档
     * 接口路径：GET/document/getFileByFileId
     */
    @ApiOperation(value = "根据文档ID查询文档")
    @GetMapping("getFileByFileId")
    public Result<DocFileDto> getFileByFileId(Long id){
        DocFileDto docFileDto =docFileService.getFileByFileId(id);
        return Result.success(docFileDto);
    }
    /**
     * 查询文档协作者列表
     * 接口路径：GET/document/pagingCollaborations
     */
    @ApiOperation(value = "查询文档协作者列表")
    @GetMapping("pagingCollaborations")
    public Result<PageResult<DocumentUserDTO>> pagingCollaborations(@RequestParam Long id,@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pageSize){
        PageResult<DocumentUserDTO> pageResult = docCollaborationsService.pagingCollaborations(id,page,pageSize);
        return Result.success(pageResult);
    }
    /**
     * 根据文件ID获取员工列表
     * 接口路径：GET/document/pagingUsers
     */
    @ApiOperation(value = "根据文件ID获取员工列表")
    @GetMapping("pagingUsers")
    public Result<List<DocUserCollaborationDTO>> pagingUsers(Long id){
        List<DocUserCollaborationDTO> collaborationDTO = docCollaborationsService.pagingUsers(id);
        return Result.success(collaborationDTO);
    }

    /**
     * 新增文件
     * 接口路径：POST/document/insertFile
     */
    @ApiOperation(value = "新增文件")
    @PostMapping("insertFile")
    public Result insertFile(@RequestBody Map<String,Object> map){
        docFileService.insertFile(map);
        return Result.success();
    }
    /**
     * 根据ID更新文档
     * 接口路径：POST/document/updateFile
     */
    @ApiOperation(value = "根据ID更新文档")
    @PostMapping("updateFile")
    public Result updateFile(@RequestBody Map<String,Object> map){
        docFileService.updateFile(map);
        return Result.success();
    }
    /**
     * 添加文档协作者信息
     * 接口路径：POST/document/insertCollaboration
     */
    @ApiOperation(value = "添加文档协作者信息")
    @PostMapping("insertCollaboration")
    public Result insertCollaboration(@RequestBody Map<String,Object> map){
        docCollaborationsService.insertCollaboration(map);
        return Result.success();
    }
    /**
     * 删除文档协作者信息
     * 接口路径：POST/document/deleteCollaboration
     */
    @ApiOperation(value = "删除文档协作者信息")
    @PostMapping("deleteCollaboration")
    public Result deleteCollaboration(@RequestBody Map<String ,Object> map){
        docCollaborationsService.deleteCollaboration(map);
        return Result.success();
    }
}
